#ifndef _WEBRTC_VADINST_H_
#define _WEBRTC_VADINST_H_
#include "vadInst.h"
#include"webrtc_vad.h"
#include "circularDeque.h"
typedef circularDeque<sData> vadRingBuffer;
typedef shared_ptr<vadRingBuffer> sVadRingBuffer;
class webrtcVadInst:public vadInst{
public:
	enum WEBRTCVADSIZE{
		WEBRTCVAD_MAX_PADDING_SIZE = 50,
		WEBRTCVAD_MAX_START_POINTS = 10,
		WEBRTCVAD_MAX_END_POINTS = 10
	};
	webrtcVadInst(vadOptions* pOptions,int iType, vadCbUtil* pCbUtil)
		:vadInst(pOptions,iType,pCbUtil)
	{
		_pInst = NULL;
		memset(_startFlags,0,sizeof(WEBRTCVAD_MAX_START_POINTS)*sizeof(int));
		memset(_endFlags,0,sizeof(WEBRTCVAD_MAX_END_POINTS)*sizeof(int));
		_iTotalPackage = 0;
		_iStartIndex = 0;
		_iEndIndex = 0;
	}
	~webrtcVadInst(){}
	void* init();
	void reset();
	void run();
	void writeBuffer(char* pData, int iLen);
	void feedData(sData pData);
	void close()
	{
		writeBuffer(NULL,-1);
		_pThread->join();	
		if(_pInst)
			WebRtcVad_Free(_pInst);
	}
private:
	sThread         _pThread;
	VadInst*        _pInst;
	sVadRingBuffer  _pVadRingBuffer;
	int             _startFlags[WEBRTCVAD_MAX_START_POINTS];
	int             _endFlags[WEBRTCVAD_MAX_END_POINTS];
	int             _iStartIndex;
	int             _iEndIndex;
	int             _iTotalPackage;
	//int             _iMaxPaddingSize;
	//int             _iMaxStartSize;
	//int             _iMaxEndSize;
};

#endif
